<?php
namespace Home\Controller;
use Think\Controller;
class DoubleColourController extends Controller {
    public function index(){
        $channel=cookie('channel');
        if($channel=='qudao303'){
            redirect(U("BigLotto/twoInOne",'',false));
        }

        indexRvent();//测算首页执行事件
        $this->assign('titleName',titleName('DoubleColour',1));//首页名称
        cookie('orderidnum','DoubleColour',604800);

        indexRequest($_REQUEST);//测算首页接收数据处理

        if(cookie('jploginHCSSQ')==''){
            cnzz_pvuv('SSQ');//执行统计
            cookie('jploginHCSSQ',1,30);
        }
        //渠道获取ID
        $channelID=obtain_channelID('SSQ');
        $this->assign('channelID',$channelID);

        $user_agent = $_SERVER['HTTP_USER_AGENT'];//用户使用的浏览器，操作系统等信息。
        if (strpos($user_agent, 'MicroMessenger') == false) {
            //非微信浏览器访问
            cookie('wxlogin',0);
        }else{
            cookie('wxlogin',1);
            getToken();
            getTicket();
            $wzurl=wxJsdkData();

            if(!empty($_REQUEST['code'])){
                cookie('code',$_REQUEST['code'],7100);
            }
            getCode($wzurl);
            getOopenid();
            cookie('uid',cookie('openid'));
        }

        $this->display("DoubelColour/doubel_index");
    }
    public function liuyao(){
        if($_REQUEST['lotteryDate']){
            cookie('lotteryDate',$_REQUEST['lotteryDate']);
            cookie('birthday',$_REQUEST['birthday']);
        }
        $this->display("DoubelColour/doubel_liuyao");
    }
    public function zhifu(){
        $this->assign('titleName',titleName('DoubleColour',2,'SSQ'));//首页名称

        cookie('timeStrto',time()+7200);//倒计时时间戳
        $user_agent = $_SERVER['HTTP_USER_AGENT'];//用户使用的浏览器，操作系统等信息。
        if (strpos($user_agent, 'MicroMessenger') == false) {
            //非微信浏览器访问
            cookie('wxlogin',0);
        }else{
            cookie('wxlogin',1);
            $this->assign('wxlogin',1);
        }
        cookie('orderidnum','DoubleColour',604800);


        if($_REQUEST['xiayao01']){//提交数据处理
            $lotteryDate=cookie('lotteryDate');
            $birthday=cookie('birthday');
            $ymdArr=explode('-',$birthday);

            cookie('zymd',$ymdArr[1].'-'.$ymdArr[2].'-'.$ymdArr[3],7200);
            cookie('zhour',$ymdArr[4],7200);
            cookie('datetype',$ymdArr[0]);

            //1少阳  2少阴  3老阳  4老阴
            $x1=$_REQUEST['xiayao01'];$x2=$_REQUEST['xiayao02'];$x3=$_REQUEST['xiayao03'];
            $s1=$_REQUEST['shangyao01'];$s2=$_REQUEST['shangyao02'];$s3=$_REQUEST['shangyao03'];
            $guaxiang=array('',$x1,$x2,$x3,$s1,$s2,$s3);
        }


        if(!empty($_REQUEST['ordernum'])){//未支付订单
            //$arrdata=M()->query("select * from sm_h5test where ordernum='{$_REQUEST['ordernum']}'");
            $arrdata[0]=S('sm_h5test|'.$_REQUEST['ordernum']);
            $zymd=$arrdata[0]['year'].'-'.str_pad($arrdata[0]['month'],2,"0",STR_PAD_LEFT).'-'.str_pad($arrdata[0]['day'],2,'0',STR_PAD_LEFT);
            cookie('zymd',$zymd,604800);
            cookie('zhour',$arrdata[0]['hour'],604800);
            cookie('datetype',$arrdata[0]['datetype']);
            $remarkArr=json_decode($arrdata[0]['date_remark'],true);
            $lotteryDate=$remarkArr['lotteryDate'];
            $guaxiang=$remarkArr['guaxiang'];

            cookie('orderid',$_REQUEST['ordernum'],604800);
        }

        $y=mb_substr(cookie('zymd'),0,4);//年
        $m=mb_substr(cookie('zymd'),5,2); //月
        $d=mb_substr(cookie('zymd'),8,2);//日
        $zyinli=yinli($y,$m,$d);


        $data=cookie('orderid');//获取订单号
        if(empty($data)&&empty($_REQUEST['ordernum'])){
            $orderid='SSQ'.date('Ymd').mt_rand(10000,99999).date('His');
            cookie('orderid',$orderid,604800);
        }

        //创建订单
        $hour=cookie('zhour');if($hour=='')$hour=0;
        $shop=cookie('orderid');
        $znickname='匿名';
        $zsex=1;
        $channel=cookie('channel');
        $imei=cookie('uid');if(cookie('uid')==''){$imei=cookie('imei');}
        $y=mb_substr(cookie('zymd'),0,4);//年
        $m=mb_substr(cookie('zymd'),5,2); //月
        $d=mb_substr(cookie('zymd'),8,2);//日
        $datetype=cookie('datetype');if($datetype=='')$datetype=0;
        defaultPrice();

        channelPay($channel,'SSQ');//查询渠道价格
        defaultPrice('DoubleColour');
        csPay($znickname,$channel);//测试价格判断
        $Data_remark=json_encode(array('lotteryDate'=>$lotteryDate,'guaxiang'=>$guaxiang,));
        $price=cookie('price');
        if(empty($_REQUEST['ordernum'])){
            $arrdata=S('sm_h5test|'.$shop);
            if(empty($arrdata)){
                $smH5testinter=array(
                    'ordernum'=>$shop, 'price'=>$price, 'username'=>$znickname, 'typeid'=>61, 'sex'=>$zsex, 'createtime'=>date('Y-m-d H:i:m'),
                    'status'=>-1, 'datetype'=>$datetype, 'year'=>$y, 'month'=>$m, 'day'=>$d, 'hour'=>$hour, 'date_remark'=>$Data_remark,
                    'appuserid'=>$imei, 'ip'=>$_SERVER['REMOTE_ADDR'], 'channel'=>$channel, 'auto_send_sms'=>0, 'place'=>0,
                );
                S('sm_h5test|'.$shop,$smH5testinter,2592000);//2592000为30天
                cacheZhiFuOrderid($shop);//支付页缓存订单操作

                $IndexController=A('Index');//Index控制器
                $IndexController->subNumber('SSQ');//提交订单次数统计
            }else if(!cookie($_REQUEST['username'])){//返回操作
                //更新订单
                $arrdata['username']=$znickname;$arrdata['datetype']=$datetype;
                $arrdata['year']=$y;$arrdata['month']=$m;$arrdata['day']=$d;$arrdata['sex']=$zsex;
                S('sm_h5test|'.$shop,$arrdata,2592000);//2592000为30天
            }
        }

        $zsex='男';
        zwmp(cookie('zymd'), cookie('zhour'),$zsex,'sizhu');
        $sizhu=I('globals.sizhu');
        $this->assign('sizhu',$sizhu);//Z四柱

        if (strpos($user_agent, 'MicroMessenger') == false) {
            //非微信浏览器访问
            if (strpos($user_agent, 'Windows') == true||strpos($user_agent,'Mac') == true) {
                //Windows 电脑访问
            }
        }else{

            $xml=wxgzhzf('SSQ','双色球',cookie('orderid'));//公众号支付回调参数
            $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
            $val = json_decode(json_encode($xmlstring),true);
            $noncestr=noncestr(15);//随机字符串
            $timestamp=time();//时间戳

            $stringA="appId=".cookie('APPID')."&nonceStr={$noncestr}&package=prepay_id={$val['prepay_id']}&signType=MD5&timeStamp={$timestamp}";
            $stringSignTemp=$stringA."&key=".cookie('wxKEY');
            $sign=strtoupper(md5($stringSignTemp));

            $this->assign('timeStamp',$timestamp);
            $this->assign('nonceStr',$noncestr);
            $this->assign('package','prepay_id='.$val['prepay_id']);
            $this->assign('signType','MD5');
            $this->assign('paySign',$sign);
            $this->assign('appId',cookie('APPID'));
        }
        //开奖时间
        $lDateArr=explode('-',$lotteryDate);
        $this->assign('lotteryDate',$lDateArr[1].'年'.$lDateArr[2].'月'.$lDateArr[3].'日 '.$lDateArr[4].'时');
        //六爻
        $classZyqg=new \Library\Zhouyiqigua();
        $zyqgData=$classZyqg->zyqgInterface($guaxiang,$sizhu);
        //dump($zyqgData);
        $this->assign('zyqgData',json_encode($zyqgData,JSON_UNESCAPED_UNICODE));


        $this->assign('csNameJump',U('DoubleColour/jieguoye','',false).'?ordernum='.cookie('orderid'));//支付成功跳转地址
        $this->assign('channel',cookie('channel'));
        
        $this->display("DoubelColour/doubel_zhifu");
    }
    public function jieguoye(){
        $this->assign('titleName',titleName('DoubleColour',3));//首页名称
        $channel=cookie('channel');
        $user_agent = $_SERVER['HTTP_USER_AGENT'];//用户使用的浏览器，操作系统等信息。
        if (strpos($user_agent, 'MicroMessenger') == false) {
            //非微信浏览器访问
            cookie('wxlogin',0);
        }else{
            cookie('wxlogin',1);
            $this->assign('wxlogin',1);

            if($_SERVER['HTTP_HOST']=='hy.yixueqm.com'){

            }else{
                getToken();
                getTicket();
            }
        }

        if($_REQUEST['ordernum']){
            $ordernum=$_REQUEST['ordernum'];
            $arrdata[0]=jieguoyeArrData($ordernum);
            $zymd=$arrdata[0]['year'].'-'.str_pad($arrdata[0]['month'],2,"0",STR_PAD_LEFT).'-'.str_pad($arrdata[0]['day'],2,'0',STR_PAD_LEFT);
            cookie('zymd',$zymd,604800);
            cookie('zhour',$arrdata[0]['hour'],604800);
            cookie('datetype',$arrdata[0]['datetype']);
            $remarkArr=json_decode($arrdata[0]['date_remark'],true);
            $lotteryDate=$remarkArr['lotteryDate'];
            $guaxiang=$remarkArr['guaxiang'];
            $numData=$remarkArr['numData'];

            cookie('orderid',$arrdata[0]['ordernum'],604800);

            if($arrdata[0]['status']!=1){
                header('location:'.U('Index/mycesuan','',false));
            }
        }

        //一对一亲算下单

        $zsex='男';
        if($zymd!=''){
            zwmp($zymd,cookie('zhour'),$zsex,'sizhu');
            $sizhu=I('globals.sizhu');//Z四柱
            fortune(I('globals.shengxiao'),I('globals.bzrizhu'));
            $this->assign('fortune',I('globals.fortune'));//流年财运
            bzcaiyun($sizhu,$zymd);
            $this->assign('arrcyd',I('globals.arrcyd'));//八字财运日
        }
        if(empty($guaxiang)){
            $guaxiang=["","1","3","3","1","4","3"];
        }
        //六爻
        $classZyqg=new \Library\Zhouyiqigua();
        $zyqgData=$classZyqg->zyqgInterface($guaxiang,$sizhu);
        $this->assign('zyqgData',json_encode($zyqgData,JSON_UNESCAPED_UNICODE));
        $this->assign('jiegua',$zyqgData['arrbengua']);

        //随机字数
//        if($ordernum='SSQ2020062836414102352'&&cookie('randNumType')==''){
//            cookie('randNumType',1,15);
//        }else{
            $this->assign('numData',$numData);
//        }

        $this->display("DoubelColour/doubel_jieguoye");
    }
    public function randNum(){
        echo 1;
        $data=$_REQUEST['numData'];
        $ordernum=cookie('orderid');
        $arrdata=jieguoyeArrData($ordernum);
        $remarkArr=json_decode($arrdata['date_remark'],true);
        $remarkArr['numData']=$data;
        $json=json_encode($remarkArr,JSON_UNESCAPED_UNICODE);

        $arrdata['date_remark']=$json;
        S('sm_h5test|'.$ordernum,$arrdata,2592000);//2592000为30天
        M()->query("update sm_h5test set date_remark='{$json}' where ordernum='{$ordernum}'");
    }

    public function pay(){//支付宝支付
        $price=cookie('price');
        $this->assign('ordername1','双色球');
        $this->assign('ordername2','知命-双色球');
        $this->display("Index/pay");

    }
    public function paywx(){//H5微信支付
        H5ZMwxzhifu('SSQ','双色球',cookie('orderid'),'DoubleColour');//知命
    }
}